{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Copy of noisystudent_svhn.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yM-HobfURgyw",
        "colab_type": "text"
      },
      "source": [
        "# Prerequisites (Download data, code and checkpoints. Preprocess)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xKAD_aCoRbHv",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!git clone https://github.com/google-research/noisystudent\n",
        "!cd noisystudent && mkdir ckpt\n",
        "!cd noisystudent && wget https://storage.googleapis.com/noisystudent/ckpts/svhn/teacher_ckpt.tar.gz -O ckpt/teacher_ckpt.tar.gz\n",
        "!cd noisystudent/ckpt && tar xzvf teacher_ckpt.tar.gz\n",
        "\n",
        "!cd noisystudent && python proc_svhn.py \\\n",
        "  --task_name=svhn \\\n",
        "  --raw_data_dir=data/svhn/raw \\\n",
        "  --output_dir=data/svhn/proc\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oSt-j5V_RmSq",
        "colab_type": "text"
      },
      "source": [
        "# Run training\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "N_aRWulEReRD",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Remember to set \"Runtime -> Change runtime type\" in the menu to use GPU. \n",
        "!cd noisystudent && python main.py \\\n",
        "    --model_name=efficientnet-b0 \\\n",
        "    --use_tpu=False \\\n",
        "    --use_bfloat16=False \\\n",
        "    --task_name=svhn \\\n",
        "    --mode=train \\\n",
        "    --train_batch_size=128 \\\n",
        "    --iterations_per_loop=1000 \\\n",
        "    --save_checkpoints_steps=1000 \\\n",
        "    --unlabel_ratio=5 \\\n",
        "    --teacher_softmax_temp=1 \\\n",
        "    --augment_name=v1 \\\n",
        "    --randaug_mag=5 \\\n",
        "    --final_base_lr=0.0002 \\\n",
        "    --weight_decay=1e-4 \\\n",
        "    --label_data_dir=./data/svhn/proc \\\n",
        "    --teacher_model_name=efficientnet-b0 \\\n",
        "    --teacher_model_path=ckpt/teacher_ckpt/model.ckpt \\\n",
        "    --model_dir=./ckpt/exp_1 \\\n",
        "    --unlabel_data_dir=./data/svhn/proc/unlabeled"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-sXU6a9uPUj-",
        "colab_type": "text"
      },
      "source": [
        "# Run evaluation"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "n-lpLpOKBiGx",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!cd noisystudent && python main.py \\\n",
        "    --model_name=efficientnet-b0 \\\n",
        "    --use_tpu=False \\\n",
        "    --use_bfloat16=False \\\n",
        "    --task_name=svhn \\\n",
        "    --mode=eval \\\n",
        "    --label_data_dir=./data/svhn/proc \\\n",
        "    --model_dir=./ckpt/exp_1"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}